﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class LS_DeliveryDetailPrintWebForm : System.Web.UI.Page //2018-12-11 zch
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            //StartDate, string EndDate, string DeliveryCode, string SelectStorage, string TargetStorage, string DeliveryType, string MaterialType, string MaterialID, bool IFCheck)
            DateTime startTime = Convert.ToDateTime(Request.QueryString["StartDate"]); //查询起时间 单一参数
            DateTime endTime = Convert.ToDateTime(Request.QueryString["EndDate"]); //查询止时间 单一参数
            string DeliveryCode = Request.QueryString["DeliveryCode"].ToString();//出库单号 单一参数
            string DeliveryType = Request.QueryString["DeliveryType"].ToString();  //出库类型 单一参数

            string SelectStorage = Request.QueryString["SelectStorage"].ToString(); //来源仓库编码
            List<int> listSourceStroageIDs = new List<int>();
            if (SelectStorage.Length > 0)
                listSourceStroageIDs.Add(int.Parse(SelectStorage));
            else
                listSourceStroageIDs = UserOperateContext.Current.Session_StorageRelated.listUserStorage;

            string TargetStorage = Request.QueryString["TargetStorage"].ToString(); //目标仓库编码
            List<int> listTargetStorageIDs = null;
            if (TargetStorage != "")
                listTargetStorageIDs = TargetStorage.Split(',').Select<string, int>(e => Convert.ToInt32(e)).ToList();

            string MaterialType = Request.QueryString["MaterialType"].ToString();
            List<string> mTypeList = UserOperateContext.Current.getMaterialTypeList(MaterialType);
            string MaterialID = Request.QueryString["MaterialID"].ToString();
            string IFCheck = Request.QueryString["IFCheck"].ToString();
            string start1 = startTime.ToString();
            string end1 = endTime.ToString();

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/LS_XDeliveryList.rdlc");


            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
         
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            I_DeliveryDAL dal = new I_DeliveryDAL();

            DataTable dt7 = dal.GetDeliveryListPrint(startTime, endTime, DeliveryCode, DeliveryType, listSourceStroageIDs, listTargetStorageIDs, mTypeList, MaterialID, IFCheck);
            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_XDeliveryList", dt7));
            this.ReportViewer1.LocalReport.Refresh();
        }
    }
}